/*----------------------------------------
 * jQuery Notes 1.0.5
------------------------------------------
 * Autor		Lukas Rydygel
 * Version		1.0.5
 * Date			24.03.2010
 * Copyright		2010 - Lukas Rydygel
 * Agency		SquareFlower Websolutions
----------------------------------------*/

(function($) {
    
    $.fn.jQueryNotes = function(settings) {

	/**
	 * @description
	 * settings for the plugin
	 */
	settings = jQuery.extend({
	    minWidth: 50,
	    minHeight: 50,
	    maxWidth: '',
	    maxHeight: '',
	    aspectRatio: false,
	    allowAdd: true,
	    allowEdit: true,
	    allowDelete: true,
	    allowHide: true,
	    allowReload: true,
	    allowLinks: true,
	    hideNotes: false,
	    loadNotes: true,
	    helper: '',
	    operator: 'jquery-notes_php/notes.php'
	}, settings);
	
	/**
	 * @description
	 * plugin object
	 */
	var jQueryNotesObj;
	
	/**
	 * @description
	 * initialize the plugin
	 */
	$(this).each(function() {
	    initPlugin(this);
	});
	
	/**
	 * @description
	 * gets properties for matched objects
	 *
	 * @param required	: int pointer
	 *
	 * @return		: none
	 */
	function getProperties(pointer) {
	    
	    jQueryNotesObj.timeout;
	    jQueryNotesObj.firstLoad = true;
	    jQueryNotesObj.add = false;
	    jQueryNotesObj.edit = false;
	    jQueryNotesObj.set = false;
	    jQueryNotesObj.move = false;
	    jQueryNotesObj.image = $('#jquery-notes_'+pointer+' img').attr('src');
	    jQueryNotesObj.width = $('#jquery-notes_'+pointer+' img').width();
	    jQueryNotesObj.height = $('#jquery-notes_'+pointer+' img').height();
	    jQueryNotesObj.left = $('#jquery-notes_'+pointer+' img').offset().left;
	    jQueryNotesObj.top = $('#jquery-notes_'+pointer+' img').offset().top;
	    
	}
	
	/**
	 * @description
	 * configurates the settings
	 *
	 * @param required	: int pointer
	 *
	 * @return		: none
	 */
	function configSettings(pointer) {
	    
	    jQueryNotesObj.minWidth = (settings.minWidth.toString().match('%')) ? percentToPixel(pointer, settings.minWidth, 'width') : jQueryNotesObj.minWidth = settings.minWidth;
	    
	    if (jQueryNotesObj.minWidth > jQueryNotesObj.width) {
		
		jQueryNotesObj.minWidth = jQueryNotesObj.width;
		jQueryNotesObj.maxWidth = ''
		
	    } else {
	    
		jQueryNotesObj.maxWidth = (settings.maxWidth.toString().match('%')) ? percentToPixel(pointer, settings.maxWidth, 'width') : jQueryNotesObj.maxWidth = settings.maxWidth;
		jQueryNotesObj.maxWidth = (jQueryNotesObj.maxWidth > jQueryNotesObj.width) ? jQueryNotesObj.width : jQueryNotesObj.maxWidth;
		
	    }
	    
	    jQueryNotesObj.minHeight = (settings.minHeight.toString().match('%')) ? percentToPixel(pointer, settings.minHeight, 'height') : jQueryNotesObj.minHeight = settings.minHeight;
	    
	    if (jQueryNotesObj.minHeight > jQueryNotesObj.height) {
		
		jQueryNotesObj.minHeight = jQueryNotesObj.height;
		jQueryNotesObj.maxHeight = ''
		
	    } else {
	    
		jQueryNotesObj.maxHeight = (settings.maxHeight.toString().match('%')) ? percentToPixel(pointer, settings.maxHeight, 'height') : jQueryNotesObj.maxHeight = settings.maxHeight;
		jQueryNotesObj.maxHeight = (jQueryNotesObj.maxHeight > jQueryNotesObj.height) ? jQueryNotesObj.height : jQueryNotesObj.maxHeight;
		
	    }
	    
	    jQueryNotesObj.aspectRatio = (settings.aspectRatio) ? jQueryNotesObj.minWidth/jQueryNotesObj.minHeight : false;
	    
	}
	
	/**
	 * @description
	 * initial the plugin and forced to load image
	 *
	 * @param required	: obj matchedObj
	 *
	 * @return		: none
	 */
	function initPlugin(matchedObj) {
	    
	    var timestamp = new Date().getTime();
	    
	    var src = $(matchedObj).attr('src');
	    
	    $(matchedObj).attr({
		src: src+'?timestamp='+timestamp
	    });
	    
	    $(matchedObj).one('load', function() {
	    
		$(this).attr({
		    src: src
		});
		
		var pointer = $('.jquery-notes-container').length;
		pointer++;
		
		jQueryNotesObj = {};
		
		setContainer(this, pointer);
		
		getProperties(pointer);
		
		configSettings(pointer);
		
		createHtml(pointer);
		
		getNotes(pointer);
		
	    });
	    
	}
	
	/**
	 * @description
	 * the matched object gets a container
	 *
	 * @param required	: obj matchedObj
	 * @param required	: int pointer
	 *
	 * @return		: none
	 */
	function setContainer(matchedObj, pointer) {
	    
	    var cssClass = $(matchedObj).attr('class');
	    
	    var style = $(matchedObj).attr('style');
	    
	    $(matchedObj).wrap('<div id="jquery-notes_'+pointer+'" class="jquery-notes-container clearfix" />').removeAttr('class', 'style').css({
		padding: 0,
		margin: 0,
		border: 'none',
		outline: 'none',
		background: 'none'
	    });
	    
	    $('#jquery-notes_'+pointer).addClass(cssClass).addClass(settings.helper).attr({
		style: style
	    });
	    
	}
	
	/**
	 * @description
	 * creates the html
	 *
	 * @param required	: int pointer
	 *
	 * @return		: none
	 */
	function createHtml(pointer) {
	    
	    $('#jquery-notes_'+pointer+' img').wrap('<div class="notes clearfix" />');
	    
	    $('#jquery-notes_'+pointer+' .notes').append('<div class="layer" />').append('<div class="loading"><div class="message"></div></div>');
	    
	    $('#jquery-notes_'+pointer+' .notes .loading').css({
		marginTop: ((jQueryNotesObj.height/2)-13)+'px'
	    }) 
	    
	    $('#jquery-notes_'+pointer+' .notes').mousedown(function(event) {
		addNote(pointer, event);
	    }).mouseup(function(event) {
		setNote(pointer, event);
	    });
	    
	    $('#jquery-notes_'+pointer).append('<div class="controller clearfix" />').width(jQueryNotesObj.width);
	    
	    (settings.loadNotes) ? $('#jquery-notes_'+pointer+' .controller').append('<a href="javascript:void(0);" class="counter" title="0 notes" />') : '';
	    
	    if (settings.allowAdd) {
		
		$('#jquery-notes_'+pointer+' .controller').append('<a href="javascript:void(0);" class="add-note" title="add note" />');
		
		$('#jquery-notes_'+pointer+' .add-note').click(function() {
		    startAdd(pointer);
		});
		
	    }
	    
	    if (settings.allowHide && settings.loadNotes) {
		
		$('#jquery-notes_'+pointer+' .controller').append('<a href="javascript:void(0);" class="hide-notes" title="hide notes" />');
		
		$('#jquery-notes_'+pointer+' .hide-notes').click(function() {
		    hideNotes(pointer);
		});
		
	    }
	    
	    if (settings.allowReload && settings.loadNotes) {
	    
		$('#jquery-notes_'+pointer+' .controller').append('<a href="javascript:void(0);" class="reload-notes" title="reload" />');
		
		$('#jquery-notes_'+pointer+' .reload-notes').click(function() {
		    reload(pointer);
		});
		
	    }
	    
	    removeLink(pointer);
	    
	}
	
	/**
	 * @description
	 * removes a surrounding link
	 *
	 * @param required	: int pointer
	 *
	 * @return		: none
	 */
	function removeLink(pointer) {
	    
	    var wrapperLink = $('#jquery-notes_'+pointer).parent('a');
	    
	    if (wrapperLink.length == 1) {
		
		$('#jquery-notes_'+pointer+' .controller').append('<a href="'+$(wrapperLink).attr('href')+'" class="link" />');
		
		$('#jquery-notes_'+pointer).unwrap();
		
	    }
	    
	}
	
	/**
	 * @description
	 * counts the notes of an image
	 *
	 * @param required	: int pointer
	 *
	 * @return		: none
	 */
	function countNotes(pointer) {
	    
	    var counter = $('#jquery-notes_'+pointer+' .notes').children('.note').length;
	    
	    if (counter == 1) {
		$('#jquery-notes_'+pointer+' .controller .counter').attr({
		    title: counter+' note'
		});
	    } else {
		$('#jquery-notes_'+pointer+' .controller .counter').attr({
		    title: counter+' notes'
		});
	    }
	    
	}
	
	/**
	 * @description
	 * start loading
	 *
	 * @param required	: int pointer
	 *
	 * @return		: none
	 */
	function startLoading(pointer, message) {
	    
	    $('#jquery-notes_'+pointer+' .notes .layer').fadeIn('middle');
	    $('#jquery-notes_'+pointer+' .notes .loading').fadeIn('middle');
	    $('#jquery-notes_'+pointer+' .notes .loading .message').text(message);
	    
	}
	
	/**
	 * @description
	 * stop loading
	 *
	 * @param required	: int pointer
	 *
	 * @return		: none
	 */
	function stopLoading(pointer) {
	    
	    jQueryNotesObj.timeout = undefined;
	    
	    (jQueryNotesObj.timeout != undefined) ? clearTimeout(jQueryNotesObj.timeout) : '';
	    
	    jQueryNotesObj.timeout = setTimeout(function() {
		
		jQueryNotesObj.timeout = undefined;
		
		$('#jquery-notes_'+pointer+' .notes .layer').fadeOut('middle');
		$('#jquery-notes_'+pointer+' .notes .loading').fadeOut('middle');
		$('#jquery-notes_'+pointer+' .notes .loading .message').text('');
		
	    }, 1000);
	    
	}
	
	/**
	 * @description
	 * gets all notes of an image
	 *
	 * @param required	: int pointer
	 *
	 * @return		: none
	 */
	function getNotes(pointer) {
	    
	    if (settings.loadNotes) {
	    
		$.ajax({
		    url: settings.operator,
		    global: false,
		    timeout: 15000,
		    dataType: 'json',
		    type: 'POST',
		    beforeSend: function() {
			(jQueryNotesObj.firstLoad) ? startLoading(pointer, 'loading notes') : '';
		    },
		    data: 'get=true&image='+jQueryNotesObj.image,
		    success: function(data) {
			
			if (data) {
			    
			    firstLoad = false;
			    
			    $.each(data, function() {
				printNote(pointer, this);
			    });
			    
			    countNotes(pointer);
			    
			    (settings.hideNotes) ? hideNotes(pointer) : '';
			    
			}
			
			stopLoading(pointer);
			
		    }
		});
	    
	    } else {
		stopLoading(pointer);
	    }
	    
	}
	
	/**
	 * @description
	 * prints a note
	 *
	 * @param required	: int pointer
	 * @param required	: obj note
	 *
	 * @return		: none
	 */
	function printNote(pointer, note) {
	    
	    $('#jquery-notes_'+pointer+' .notes').append(function() {
		
		if (note.LINK != '') {
		    
		    if (note.NOTE != '') {
			return (settings.allowLinks) ? '<div id="n_'+pointer+'-'+note.ID+'" class="note"><div class="border"><div class="bg"><a href="'+note.LINK+'"></a></div></div></div><div id="t_'+pointer+'-'+note.ID+'" class="text">'+note.NOTE+'</div>' : '<div id="n_'+pointer+'-'+note.ID+'" class="note"><div class="border"><div class="bg"></div></div></div><div id="t_'+pointer+'-'+note.ID+'" class="text">'+note.NOTE+'</div>';
		    } else {
			return (settings.allowLinks) ? '<div id="n_'+pointer+'-'+note.ID+'" class="note"><div class="border"><div class="bg"><a href="'+note.LINK+'"></a></div></div></div><div id="t_'+pointer+'-'+note.ID+'" class="text">'+note.LINK+'</div>' : '<div id="n_'+pointer+'-'+note.ID+'" class="note"><div class="border"><div class="bg"></div></div></div><div id="t_'+pointer+'-'+note.ID+'" class="text">'+note.LINK+'</div>';
		    }
		    
		} else {
		    return '<div id="n_'+pointer+'-'+note.ID+'" class="note"><div class="border"><div class="bg"></div></div></div><div id="t_'+pointer+'-'+note.ID+'" class="text">'+note.NOTE+'</div>';
		}
		
	    });
	    
	    if (settings.allowDelete || settings.allowEdit) {
		
		$('#jquery-notes_'+pointer+' .notes #n_'+pointer+'-'+note.ID).append('<a href="javascript:void(0);" class="settings" title="settings" />');
		
		$('#jquery-notes_'+pointer+' .notes #n_'+pointer+'-'+note.ID+' .settings').click(function() {
		    openSettings(pointer, note.ID);
		});
		
	    }
	    
	    var position = {
		'left': percentToPixel(pointer, note.LEFT, 'left'),
		'top': percentToPixel(pointer, note.TOP, 'top'),
		'width': percentToPixel(pointer, note.WIDTH, 'width'),
		'height': percentToPixel(pointer, note.HEIGHT, 'height')
	    };
	    
	    $('#jquery-notes_'+pointer+' .notes #n_'+pointer+'-'+note.ID).css({
		left: position.left+'px',
		top: position.top+'px',
		width: position.width+'px',
		height: position.height+'px'
	    }).hover(function() {
		focusOnNote(pointer, note.ID);
	    }, function() {
		focusOffNote(pointer, note.ID);
	    });
	    
	    $('#jquery-notes_'+pointer+' .notes #t_'+pointer+'-'+note.ID).css({
		left: position.left+'px',
		top: (parseFloat(position.top)+parseFloat(position.height))+'px'
	    });
	    
	}
	
	/**
	 * @description
	 * focus on a note
	 *
	 * @param required	: int pointer
	 * @param required	: int id
	 *
	 * @return		: none
	 */
	function focusOnNote(pointer, id) {
	    
	    if (!jQueryNotesObj.add && !jQueryNotesObj.edit) {
		
		$('#jquery-notes_'+pointer+' .notes .note').addClass('offFocus');
		
		if (id != undefined) {
		    
		    $('#jquery-notes_'+pointer+' .notes #n_'+pointer+'-'+id).removeClass('offFocus').addClass('onFocus').children('.settings').show();
		    
		    $('#jquery-notes_'+pointer+' .notes #t_'+pointer+'-'+id).show().css({
			zIndex: 9990
		    });
		    
		}
		
	    }
	    
	}
	
	/**
	 * @description
	 * focus off a note
	 *
	 * @param required	: int pointer
	 * @param required	: int id
	 *
	 * @return		: none
	 */
	function focusOffNote(pointer, id) {
	    
	    if (!jQueryNotesObj.add && !jQueryNotesObj.edit) {
		
		$('#jquery-notes_'+pointer+' .notes .note').removeClass('offFocus');
		
		if (id != undefined) {
		    
		    $('#jquery-notes_'+pointer+' .notes #n_'+pointer+'-'+id).removeClass('onFocus').children('.settings').hide();
		    
		    $('#jquery-notes_'+pointer+' .notes #t_'+pointer+'-'+id).hide().css({
			zIndex: 'auto'
		    });
		    
		}
		
	    }
	    
	}
	
	/**
	 * @description
	 * add a new note
	 *
	 * @param required	: int pointer
	 * @param required	: obj event
	 *
	 * @return		: none
	 */
	function addNote(pointer, event) {
	    
	    if (jQueryNotesObj.add && !jQueryNotesObj.set) {
	    
		jQueryNotesObj.set = true;
		jQueryNotesObj.move = true;
		
		var position = {};
		
		position.left = event.pageX-jQueryNotesObj.left;
		position.top = event.pageY-jQueryNotesObj.top;
		
		$('#jquery-notes_'+pointer+' .notes').append('<div class="note select"><div class="border"><div class="bg"></div></div></div>');
		
		position.maxLeft = jQueryNotesObj.width-jQueryNotesObj.minWidth;
		position.maxTop = jQueryNotesObj.height-jQueryNotesObj.minHeight;
		
		position.left = (position.left > position.maxLeft) ? position.maxLeft : position.left;
		position.top = (position.top > position.maxTop) ? position.maxTop : position.top;
		
		$('#jquery-notes_'+pointer+' .notes .select').css({
		    width: jQueryNotesObj.minWidth,
		    height: jQueryNotesObj.minHeight,
		    left: position.left,
		    top: position.top,
		    cursor: 'move'
		}).draggable({
		    containment: 'parent',
		    cursor: 'move'
		}).resizable({
		    containment: 'parent',
		    minWidth: jQueryNotesObj.minWidth,
		    minHeight: jQueryNotesObj.minHeight,
		    maxWidth: jQueryNotesObj.maxWidth,
		    maxHeight: jQueryNotesObj.maxHeight,
		    aspectRatio: jQueryNotesObj.aspectRatio,
		    handles: 'se'
		});
		
	    }
	    
	}
	
	/**
	 * @description
	 * set a new note
	 *
	 * @param required	: int pointer
	 * @param required	: obj event
	 *
	 * @return		: none
	 */
	function setNote(pointer, event) {
	    
	    if (jQueryNotesObj.add && jQueryNotesObj.set && jQueryNotesObj.move) {
		
		jQueryNotesObj.move = false;
		
		$('#jquery-notes_'+pointer+' .notes .select').append('<div class="text-box"><textarea name="note"></textarea><br /></div>');
		
		$('#jquery-notes_'+pointer+' .notes .select .text-box').append(function() {
		    return (settings.allowLinks) ? '<input type="text" name="link" value="http://" /><br />' : false;
		}).append('<a href="javascript:void(0);" class="save-note" title="save note"></a><a href="javascript:void(0);" class="cancel-note" title="cancel"></a>');
		
		$('#jquery-notes_'+pointer+' .notes .select .text-box .save-note').click(function() {
		    saveNote(pointer, null, 'add');
		});
		
		$('#jquery-notes_'+pointer+' .notes .select .text-box .cancel-note').click(function() {
		    
		    $('#jquery-notes_'+pointer+' .controller .cancel-note').removeClass('cancel-note').attr({
			title: 'add note'
		    });
		    
		    abort(pointer);
		    
		});
		
	    }
	    
	}
	
	/**
	 * @description
	 * save a note
	 *
	 * @param required	: int pointer
	 * @param required	: int id
	 *
	 * @return		: none
	 */
	function saveNote(pointer, id, operation) {
	    
	    var note = $('#jquery-notes_'+pointer+' .notes .select .text-box textarea').val();
	    var link = $('#jquery-notes_'+pointer+' .notes .select .text-box input').val();
	    
	    link = (link == undefined) ? '' : link;
	    
	    var position = getNotePosition(pointer);
	    
	    $.ajax({
		url: settings.operator,
		global: false,
		timeout: 15000,
		dataType: 'json',
		type: 'POST',
		beforeSend: function() {
		    (id == undefined) ? startLoading(pointer, 'saving note') : startLoading(pointer, 'editing note');	
		},
		data: operation+'=true&image='+jQueryNotesObj.image+'&id='+id+'&position='+position.left+','+position.top+','+position.width+','+position.height+'&note='+note+'&link='+link,
		success: function(data) {
		    
		    if (data) {
			
			$('#jquery-notes_'+pointer+' .controller .cancel-note').removeClass('cancel-note').attr({
			    title: 'add note'
			});
			
			reload(pointer);
			
		    } else {
			
			stopLoading(pointer);
			
			alert('Can\'t save note.');
			
		    }
		    
		}
	    });
	    
	}
	
	/**
	 * @description
	 * delete a note
	 *
	 * @param required	: int pointer
	 * @param required	: int id
	 *
	 * @return		: none
	 */
	function deleteNote(pointer, id) {
	    
	    if (settings.allowDelete) {
		
		$.ajax({
		    url: settings.operator,
		    global: false,
		    timeout: 15000,
		    dataType: 'json',
		    type: 'POST',
		    beforeSend: function() {
			startLoading(pointer, 'deleting note');
		    },
		    data: 'delete=true&image='+jQueryNotesObj.image+'&id='+id,
		    success: function(data) {
			
			if (data) {
			    reload(pointer);
			} else {
			    
			    stopLoading(pointer);
			    
			    alert('Can\'t delete note.');
			    
			}
			
		    }
		});
		
	    }
	    
	}
	
	/**
	 * @description
	 * start adding a note
	 *
	 * @param required	: int pointer
	 *
	 * @return		: none
	 */
	function startAdd(pointer) {
	    
	    if (settings.allowAdd) {
		
		if (jQueryNotesObj.add) {
		    
		    $('#jquery-notes_'+pointer+' .controller .cancel-note').removeClass('cancel-note').attr({
			title: 'add note'
		    });
		    
		    abort(pointer);
		    
		} else if (!jQueryNotesObj.add && !jQueryNotesObj.edit) {
		    
		    abort(pointer);
		    
		    focusOnNote(pointer);
		    
		    jQueryNotesObj.add = true;
		    
		    $('#jquery-notes_'+pointer+' .controller .add-note').addClass('cancel-note').attr({
			title: 'cancel'
		    });
		    
		}
		
	    }
	    
	}
	
	/**
	 * @description
	 * opens note settings
	 *
	 * @param required	: int pointer
	 * @param required	: int id
	 *
	 * @return		: none
	 */
	function openSettings(pointer, id) {
	    
	    if ((settings.allowEdit || settings.allowDelete) && !jQueryNotesObj.edit && !jQueryNotesObj.add) {
		
		jQueryNotesObj.edit = true;
		
		$('#jquery-notes_'+pointer+' .notes #n_'+pointer+'-'+id).addClass('select');
		
		var note = $('#jquery-notes_'+pointer+' .notes #t_'+pointer+'-'+id).text();
		var link = $('#jquery-notes_'+pointer+' .notes #n_'+pointer+'-'+id+' .border .bg a').attr('href');
		
		$('#jquery-notes_'+pointer+' .notes #n_'+pointer+'-'+id+' .settings').remove();
		$('#jquery-notes_'+pointer+' .notes #t_'+pointer+'-'+id).remove();
		$('#jquery-notes_'+pointer+' .notes #n_'+pointer+'-'+id+' .border .bg a').remove();
		
		note = (note == link) ? '' : note;
		link = (link == null || link == '') ? 'http://' : link;
		
		$('#jquery-notes_'+pointer+' .notes .select').append('<div class="text-box" />');
		
		if (settings.allowEdit) {
		    
		    $('#jquery-notes_'+pointer+' .notes .select .text-box').append('<textarea name="note">'+note+'</textarea><br />').append(function() {
			return (settings.allowLinks) ? '<input type="text" name="link" value="'+link+'" /><br />' : false;
		    }).append('<a href="javascript:void(0);" class="edit-note" title="edit note" />');
		    
		}
		
		$('#jquery-notes_'+pointer+' .notes .select .text-box').append('<a href="javascript:void(0);" class="cancel-note" title="cancel" />');
		
		(settings.allowDelete) ? $('#jquery-notes_'+pointer+' .notes .select .text-box').append('<a href="javascript:void(0);" class="delete-note" title="delete note" />') : '';
		
		$('#jquery-notes_'+pointer+' .notes .select').draggable({
		    containment: 'parent',
		    cursor: 'move'
		}).resizable({
		    containment: 'parent',
		    minWidth: jQueryNotesObj.minWidth,
		    minHeight: jQueryNotesObj.minHeight,
		    maxWidth: jQueryNotesObj.maxWidth,
		    maxHeight: jQueryNotesObj.maxHeight,
		    aspectRatio: jQueryNotesObj.aspectRatio,
		    handles: 'se'
		});
		
		$('#jquery-notes_'+pointer+' .notes .select .text-box .edit-note').click(function() {
		    saveNote(pointer, id, 'edit');
		});
		
		$('#jquery-notes_'+pointer+' .notes .select .text-box .cancel-note').click(function() {
		    reload(pointer);
		});
		
		$('#jquery-notes_'+pointer+' .notes .select .text-box .delete-note').click(function() {
		    deleteNote(pointer, id);
		});
		
	    }
	    
	}
	
	/**
	 * @description
	 * hides notes
	 *
	 * @param required	: int pointer
	 *
	 * @return		: none
	 */
	function hideNotes(pointer) {
	    
	    if (!jQueryNotesObj.add && !jQueryNotesObj.edit) {
		
		if ($('#jquery-notes_'+pointer+' .controller .hide-notes').hasClass('show-notes')) {
		    
		    $('#jquery-notes_'+pointer+' .notes .note').css({
			visibility: 'visible'
		    });
		    
		    $('#jquery-notes_'+pointer+' .controller .hide-notes').removeClass('show-notes').attr({
			title: 'hide notes'
		    });
		
		} else {
		    
		    $('#jquery-notes_'+pointer+' .notes .note').css({
			visibility: 'hidden'
		    });
		    
		    $('#jquery-notes_'+pointer+' .controller .hide-notes').addClass('show-notes').attr({
			title: 'show notes'
		    });
		    
		}
		
	    }
	    
	}
	
	/**
	 * @description
	 * reload notes
	 *
	 * @param required	: int pointer
	 *
	 * @return		: none
	 */
	function reload(pointer) {
	    
	    $('#jquery-notes_'+pointer+' .notes .note').remove();
	    $('#jquery-notes_'+pointer+' .notes .text').remove();
	    
	    getProperties(pointer);
	    
	    getNotes(pointer);
	    
	}
	
	/**
	 * @description
	 * cencel and reset
	 *
	 * @param required	: int pointer
	 *
	 * @return		: none
	 */
	function abort(pointer) {
	    
	    $('#jquery-notes_'+pointer+' .notes .select').remove();
	    
	    getProperties(pointer);
	    
	    focusOffNote(pointer);
	    
	}
	
	/**
	 * @description
	 * gets the position of a selcted note
	 *
	 * @param required	: int pointer
	 *
	 * @return		: obj
	 */
	function getNotePosition(pointer) {
	    
	    return {
		'left': pixelToPercent(pointer, $('#jquery-notes_'+pointer+' .notes .select').css('left'), 'left'),
		'top': pixelToPercent(pointer, $('#jquery-notes_'+pointer+' .notes .select').css('top'), 'top'),
		'width': pixelToPercent(pointer, $('#jquery-notes_'+pointer+' .notes .select').css('width'), 'width'),
		'height': pixelToPercent(pointer, $('#jquery-notes_'+pointer+' .notes .select').css('height'), 'height')
	    };
	    
	}
	
	/**
	 * @description
	 * transforms pixel to percent
	 *
	 * @param required	: int pointer
	 * @param required	: int pixel
	 * @param required	: string type
	 *
	 * @return		: float
	 */
	function pixelToPercent(pointer, pixel, type) {
	    
	    pixel = parseInt(pixel.toString().replace('px', ''));
	    
	    switch (type) {
		
		case 'left':
		case 'width':
		    var percent = (100/jQueryNotesObj.width)*pixel;
		break;
		case 'top':
		case 'height':
		    var percent = (100/jQueryNotesObj.height)*pixel;
		break;
		
	    }
	    
	    return percent;
	    
	}
	
	/**
	 * @description
	 * transforms percent to pixel
	 *
	 * @param required	: int pointer
	 * @param required	: float percent
	 * @param required	: string type
	 *
	 * @return		: int
	 */
	function percentToPixel(pointer, percent, type) {
	    
	    percent = parseFloat(percent.toString().replace('%', ''));
	    
	    switch (type) {
		
		case 'left':
		case 'width':
		    var pixel = (percent/100)*jQueryNotesObj.width;
		break;
		case 'top':
		case 'height':
		    var pixel = (percent/100)*jQueryNotesObj.height;
		break;
		
	    }
	    
	    return pixel;
	    
	}
	
    };

})(jQuery);